# -*- coding: utf-8 -*-
"""
Created on Tue Sep 28 19:23:40 2021

@author: think
"""

from ipReplacement import initReplacement, endReplacement
from createKeys import createKeys
from iterTransform import iterTransform



M = []
origin_key = []

#输入为16位16进制数
m = input().lower()
k = input().lower()

for i in range(16):
    M.extend(list('{:0>4b}'.format(int(m[i], 16))))
    origin_key.extend(list('{:0>4b}'.format(int(k[i], 16))))

for i in range(64):
    M[i] = int(M[i])
    origin_key[i] = int(origin_key[i])

keys = createKeys(origin_key)
#如果要解密的话就去掉下面语句的注释；如果解密的话就把它注释掉
#keys = keys[::-1]


C = initReplacement(M)
C = iterTransform(C, keys)
C = endReplacement(C)

for i in range(len(C)):
    C[i] = str(C[i])
    
for i in range(len(C) // 4):
    x = ''.join(C[i * 4 : (i+1) * 4])
    print('{:x}'.format(int(x, 2)), end = '')
print()